import {
    getOrderAlllist
} from '../../../api/index.js'
import axios from "axios"

export default {
    props: {
        handleStep: Function,
        handleOrderId: Function
    },
    data() {
        return {
            imgBaseUrl: process.env.VUE_APP_WAREHOUSE_API,
            src: require('../../../assets/test02.jpg'),
            orderList: [{totalPrice: '00.00'}],
            totalPrice: 0.01,
            orderNumber: ''
        }
    },
    methods: {
        httpGetOrderList() {
            const loading = this.$loading({
                lock: true,
                text: '正在获取...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            })
            getOrderAlllist({
                orderNo: this.$route.query.orderNumber,
                page: 1,
                pageSize: 100
            }).then(res => {
                if (res.data.code === 200) {
                    let result = res.data.result.list
                    // 计算系统合计
                    result.forEach(item=>{
                        item.titleList.forEach(list=>{
                            let totalSystem = 0
                            list.children.forEach(child=>{
                                totalSystem += parseInt(child.projecetPrice)
                            })
                            list.totalSystem = totalSystem.toFixed(2)
                        })
                    })
                    this.orderList = result
                }
                loading.close()
            }).catch(err => {
                loading.close()
                // this.$message.error("获取订单列表失败")
            })
        },
        // 提交订单
        submitOrder() {
            this.handleOrderId(this.$route.query.orderNumber)
            this.handleStep()
        },
        //从路由中保存token
        cacheToken() {
            let token = this.$route.query.token
            if (token) {
                axios.defaults.headers.common["ACCESS_TOKEN"] = token
                this.$store
                    .dispatch("user/saveToken", token).then(()=>{
                       setTimeout(()=>{
                           this.httpGetOrderList()
                       },500)
                })
            }else {
                this.httpGetOrderList()
            }
        }

    },
    created() {
        this.cacheToken()
    }
};
